package com.genexususa.eo.bing.data.wsSubclasses;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.AdGroupAdRotation;
import com.genexususa.eo.bing.data.GxItemException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxAdGroupAdRotation extends AdGroupAdRotation {
    private long gxAdGroupId;

    public GxAdGroupAdRotation(Element element) throws IllegalArgumentException, GxItemException {
        if (element.getElementsByTagName("GxAdGroupId").getLength() > 0 &&
            element.getElementsByTagName("GxAdGroupId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxAdGroupId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxAdGroupId = Long.valueOf(((Node)element.getElementsByTagName("GxAdGroupId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external AdGroup id");
        }
        if (element.getElementsByTagName("BingAdGroupId").getLength() > 0 &&
            element.getElementsByTagName("BingAdGroupId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingAdGroupId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setAdGroupId(Long.valueOf(((Node) element.getElementsByTagName("BingAdGroupId").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("AdRotation").getLength() > 0 ) {
            this.setAdRotation(new GxAdRotation((Element)element.getElementsByTagName("AdRotation").item(0)));
        }
    }

    public long getGxAdGroupId() {
        return gxAdGroupId;
    }

    public void setGxAdGroupId(long gxAdGroupId) {
        this.gxAdGroupId = gxAdGroupId;
    }
}
